<?php

declare(strict_types=1);

namespace App\CustHub\Controller;

use App\CustHub\Annotation\ApiAuth;
use App\CustHub\Annotation\VerifySignature;
use App\CustHub\Request\LicenseRequest;
use App\CustHub\Service\ChRobotService;
use App\CustHub\Service\ChSeatService;
use App\CustHub\Service\LicenseService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\PostMapping;

#[Controller(prefix: 'ch/license'),ApiAuth,VerifySignature]
class LicenseController extends BaseController
{
    #[Inject]
    protected LicenseService $service;

    #[Inject]
    protected ChSeatService $seatService;

    #[Inject]
    protected ChRobotService $robotService;

    /**
     * 绑定席位
     * @param LicenseRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('bind')]
    public function bind(LicenseRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->bindLicense($request->all()) ? $this->success() : $this->error();
    }

    /**
     * 批量绑定席位
     * @param LicenseRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('batchBind')]
    public function batchBind(LicenseRequest $request): \Psr\Http\Message\ResponseInterface
    {
        $this->service->batchBindLicense($request->all());
        return $this->success('操作成功，请稍后刷新页面查看');
    }

    #[PostMapping('changeBind')]
    public function changeBind(LicenseRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->changeBindLicense($request->all()) ? $this->success() : $this->error();
    }

    /**
     * 获取席位列表
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('getSeatList')]
    public function getSeatList(): \Psr\Http\Message\ResponseInterface
    {
        return $this->success($this->seatService->getSeatList($this->request->all()));
    }

    /**
     * 获取机器人列表
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('getRobotList')]
    public function getRobotList(): \Psr\Http\Message\ResponseInterface
    {
        return $this->success($this->robotService->getRobotList($this->request->all()));
    }
}